package com.zzedu.common.core.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Map;

/**
 * Entity基类
 *
 * @author smarthome
 */
public class ExtendEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 请求参数
     */
    @TableField(exist = false)
    private Map<String, Object> params;

    /**
     * 当前记录起始索引
     */
    @TableField(exist = false)
    private Long pageNum = 1l;

    /**
     * 每页显示记录数
     */
    @TableField(exist = false)
    private Long pageSize = 20l;

    /**
     * 排序列
     */
    @TableField(exist = false)
    private String orderByColumn;

    /**
     * 排序的方向desc或者asc
     */
    @TableField(exist = false)
    private String isAsc = "asc";

    @JsonIgnore
    public Long getPageNum() {
        return pageNum;
    }

    @JsonSetter("pageNum")
    public void setPageNum(Long pageNum) {
        this.pageNum = pageNum;
    }

    @JsonIgnore
    public Long getPageSize() {
        return pageSize;
    }

    @JsonSetter("pageSize")
    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    @JsonIgnore
    public String getOrderByColumn() {
        return orderByColumn;
    }

    @JsonSetter("orderByColumn")
    public void setOrderByColumn(String orderByColumn) {
        this.orderByColumn = orderByColumn;
    }

    @JsonIgnore
    public String getIsAsc() {
        return isAsc;
    }

    @JsonSetter("isAsc")
    public void setIsAsc(String isAsc) {
        this.isAsc = isAsc;
    }

    @JsonIgnore
    public Map<String, Object> getParams() {
        return params;
    }

    @JsonSetter("params")
    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    @JsonIgnore
    public IPage getPageDTO() {
        return PageDTO.of(getPageNum(), getPageSize());
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
